'use strict';
//define(['js/module.js'], function(controllers) {
	angular.module('backcenter.personSelectSingle', [])

	.controller('personSelectSingleCtrl'
			,['$scope', '$rootScope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($scope, $rootScope, BizData, $uibModalInstance, params, title
					   ) {
		$scope.headerText = '----------我是系统客户区personSelectSingleCtrl控制器！id为-->'+$scope.$id+'开始----------';
		$scope.footerText = '----------我是系统客户区personSelectSingleCtrl控制器！id为-->'+$scope.$id+'结束----------';


		var Model = this;


		Model.gridRowClick = function(event){
			
		}

		Model.gridRowDblClick = function(event){
			Model.ok();
		}
		
		var options = {};
		options.container = Model;
		options.concept = 'SaOpperson';
		options.name = 'dataPerson';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '';
		options.reader = '/backcenter/person/selectSingle/query';
		options.writer = '';
		options.deleter = '';
		options.idColumnDefine = "sID";
		options.idColumnName = "sID";
		options.isTree = false;
		options.parentRelation = 'sParent';
		options.nodeKindRelation = 'sNodeKind';
		options.nodeLevelRelation = 'sLevel';
		options.pathRelation = 'sFID';
		options.directDeleteMode = true;
		options.limit = 10;
		
		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataPersonIndexChanged;
		options.onBeforeNew = Model.dataPersonBeforeNew;
		options.onAfterNew = Model.dataPersonAfterNew;
		options.onBeforeDelete = Model.dataPersonBeforeDelete;
		options.onAfterDelete = Model.dataPersonAfterDelete;
		options.onValueChanged = Model.dataPersonValueChanged;
		options.onDataChanged = Model.dataPersonDataChanged;
		
		$scope.dataPerson = new BizData(options);

		//监视对象中的所有变动
		$scope.dataPerson.deregRows = $scope.$watch('dataPerson.rows',$scope.dataPerson.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
    		Model.title = title;  
    		Model.params = params;  
//    		console.log('params-->',params);
    		/*
    		if(params.id){
    			$scope.dataPerson.filter = "SaOpperson.sMainOrgID='"+params.id+"'";
    		}
    		*/
//    		$scope.dataPerson.refreshData();
        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	var sourceRow = $scope.dataPerson.rows[$scope.dataPerson.currentIndex];
	    	var row = {};
			//循环行中的列，判断变化点是哪一个
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	
	    	data.push(row);
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////
	    



		
		return Model;
	    
	    
	}	
	
//});
